package exer;

/**
 * @author tongchen
 * @create 2023-01-25 11:14
 */
public class TestDieLock {
 static Object loker1=new Object();
 static Object loker2=new Object();

    public static void main(String[] args) {
        //创建线程1
         Thread t1 =new Thread(()->{
                    synchronized (loker1){
                        System.out.println(Thread.currentThread().getName()+"loker1");
                        //等待其他线程插入
                        try {
                            loker1.wait(1000);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        synchronized (loker2){
                            System.out.println(Thread.currentThread().getName()+"loker2");
                        }
                    }
                 },"t1");
         t1.start();
          Thread t2 =new Thread(()->{
                     synchronized (loker2){
                         System.out.println(Thread.currentThread().getName()+"loker2");
                         try {
                             loker2.wait(1000);
                         } catch (InterruptedException e) {
                             throw new RuntimeException(e);
                         }
                         synchronized (loker1){
                             System.out.println(Thread.currentThread().getName()+loker1);
                         }
                     }
                  },"t2");
          t2.start();
    }
}
